/**
 * @a https://leetcode.cn/problems/sum-of-two-integers/
 */

#include "common.h"

class Solution
{
public:
    int getSum(int a, int b)
    {
        int sum_without_carry = a ^ b;
        unsigned int carry = a & b;
        while (carry)
        {
            int tmp = sum_without_carry ^ (carry << 1);
            carry = sum_without_carry & (carry << 1);
            sum_without_carry = tmp;
        }
        return sum_without_carry;
    }
};

class Solution
{
public:
    int getSum(int a, int b)
    {
        while(b)
        {
            int x = a ^ b;
            int carry = (a & b) << 1;
            a = x;
            b = carry;
        }
        return a;
    }
};